package com.fr.web.platform.entry;

import com.fr.base.StringUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.schedule.ScheduleContext;
import com.fr.schedule.dao.JdbcDaoManager;

public abstract class BaseEntry
  implements Entry
{
  public static final String ID = "id";
  public static final String PARENTID = "parent";
  public static final String DISPLAYNAME = "name";
  public static final String DESCRIPTION = "description";
  public static final int IDTYPE = 4;
  public static final int PARENTIDTYPE = 4;
  public static final int DISPLAYNAMETYPE = 12;
  public static final int DESCRIPTIONTYPE = 12;
  private long id = -1L;
  private long parentId;
  private String displayName;
  private String description;

  public BaseEntry()
  {
  }

  public BaseEntry(String paramString)
  {
    this.displayName = paramString;
  }

  public BaseEntry(String paramString1, String paramString2)
  {
    this.displayName = paramString1;
    this.description = paramString2;
  }

  public JSONObject createJSONConfig()
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    localJSONObject.put("id", getTypePrefix() + getId());
    localJSONObject.put("type", getTypePrefix());
    localJSONObject.put("parentId", "0" + getParentId());
    localJSONObject.put("text", getDisplayName());
    localJSONObject.put("description", getDescription());
    return localJSONObject;
  }

  public void parseJSON(JSONObject paramJSONObject)
    throws JSONException
  {
    setDisplayName(paramJSONObject.getString("text"));
    setDescription(paramJSONObject.getString("description"));
    setParentId(paramJSONObject.getLong("parentId"));
    if ((paramJSONObject.has("id")) && (StringUtils.isNotBlank(paramJSONObject.getString("id"))))
      setId(paramJSONObject.getLong("id"));
  }

  public abstract String getTypePrefix();

  public boolean appendToFolder(FolderEntry paramFolderEntry)
  {
    setParentId(paramFolderEntry.getId());
    return ScheduleContext.getJdbcDaoManager().saveOrUpdate(this);
  }

  public void setId(long paramLong)
  {
    this.id = paramLong;
  }

  public long getId()
  {
    return this.id;
  }

  public void setParentId(long paramLong)
  {
    this.parentId = paramLong;
  }

  public long getParentId()
  {
    return this.parentId;
  }

  public void setDisplayName(String paramString)
  {
    this.displayName = paramString;
  }

  public String getDisplayName()
  {
    return this.displayName;
  }

  public void setDescription(String paramString)
  {
    this.description = paramString;
  }

  public String getDescription()
  {
    return this.description;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof BaseEntry))
      return false;
    BaseEntry localBaseEntry = (BaseEntry)paramObject;
    return ((localBaseEntry.id == this.id) && (localBaseEntry.parentId == this.parentId) && (ComparatorUtils.equals(localBaseEntry.displayName, this.displayName)) && (ComparatorUtils.equals(localBaseEntry.description, this.description)));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    BaseEntry localBaseEntry = (BaseEntry)super.clone();
    return localBaseEntry;
  }
}